#ifndef SERVERCONNECTION_H
#define SERVERCONNECTION_H

#include <QTcpSocket>
#include <QApplication>

class ServerConnection : public QObject
{
    Q_OBJECT

public:
    // Parameterized constructor
    ServerConnection(QString name, QString host, int port, QString authName, QString password, QString filterString);
    ServerConnection(QString name, QString host, int port, QString authName, QString password, QString filterString, bool writeEnabled);
    ~ServerConnection(); // Deconstructor
private:
    QTcpSocket* socket; // Pointer to a QTcpSocket that will be this instance's connection
    QString name;   // Name of this connection
    QString host;   // Hostname that this connection will be established to
    int port;   // Port number of the host that this connection will connect to
    QString authName;   // Login name for the server that this will connect to
    QString password;   // Password for the login name of the server this will connect to
    QString authString; // The authentication string used to connect to the server
    QString filterString;   // The filter string entered by user in order to filter via server
    bool writeEnabled; // Lets this instance know if it can write to the connection or not
    bool connected; // Connected to server?
public:
    QString getPacket(); // Gets packet that is waiting
    void connectToServer(); // Connect to the server using name, host, port, authname, password attributes given during object creation
    void disconnectFromServer(); // Disconnect from the currently connected server
    QString getName(); // Returns the name given to this connection
    QString getHostName(); // Returns the hostname of the server that this object connects to
    int getPortNumber(); // Returns the port number used to connect
    QString getUserName(); // Returns the username used to log onto server
    QString getPassword(); // Returns the password associated with the username used to log onto the server
    QString getFilterString(); // Returns the filter string that was set for this server
    bool isWriteEnabled(); // Is this instance able to write to socket?
    void setWriteEnabled(bool writeEnabled); // Sets if this socket can be written to

    // change any parameters of this connection
    void changeParameters(QString name, QString host, int port, QString authName, QString password, QString filterString);
    void writeToSocket(QString aprsPacket); // writes the packet that is sent to this connection
    bool isConnected(); // Connected to server??
signals:
    void newData(QString); // Sends the latest packet to the controller object
private slots:
    void newDataFromConnection(); // receives data from connection and emits newData
};

#endif // SERVERCONNECTION_H
